<template>
  <view class="container">
    <view class="top">
      <view class="cover-bg">
        <image class="bg-img" :src="categoryInfo.home_image"></image>
      </view>
      <view class="desc-box">
        <view class="desc-row">
          <view class="cover-img">
            <image class="avatar-img" :src="categoryInfo.home_image"></image>
          </view>
          <view class="desc-content">
            <view class="title">{{title}}</view>
            <view class="desc">{{categoryInfo.description}}</view>
          </view>
        </view>
        <view class="share-row">
          <view class="video-count">{{categoryInfo.video_count}}部影视</view>
          <button class="share-btn" open-type="share">
            <u-icon name="share" color="#fff" size="30" class="share-icon" />
          </button>
        </view>
      </view>
      <view class="bg"></view>
    </view>
    <view class="middle">
      <view class="video-box">
        <VideoList :videoList="videoList" />
        <u-loadmore :status="uploadMoreStatus" />
      </view>
    </view>
  </view>
</template>

<script>
import * as api from '@/api/api';
import VideoList from '@/components/video-list/video-list';
export default {
  name: "CategoryVideo",
  components: {
    VideoList
  },
  data() {
    return {
      cateId: null,
      title: '',
      categoryInfo: {},
      videoList: [],
      currentPage: 1,
      uploadMoreStatus: 'loadmore',
      isLastPage: false
    };
  },
  onLoad(e) {
    this.cateId = e.cateId || null;
    this.title = e.name || '';
    uni.setNavigationBarTitle({title: e.name});
    if (this.cateId) {
      this.getCategoryDetail();
      this.getVideoListByCateId();
    }
  },
  created() {},
  mounted() {},
  methods: {
    // 分类详情
    async getCategoryDetail() {
      const {data: res} = await api.getCategoryDetail(this.cateId);
      this.categoryInfo = res.data;
    },
    // 栏目下视频列表
    async getVideoListByCateId() {
      const params = {
        categories: this.cateId,
        page: this.currentPage
      };
      const {data: res} = await api.getVideoList(params);
      if (res.code === 1) {
        if (res.data.length < 10) {
          this.isLastPage = true;
          this.uploadMoreStatus = 'nomore';
        }
        this.videoList = this.videoList.concat(res.data);
      }
    },
    onReachBottom() {
      if (!this.isLastPage) {
        this.uploadMoreStatus = 'loading';
        this.currentPage += 1;
        this.getVideoListByCateId();
      }
    }
  },
};
</script>
<style lang="scss" scoped>
  .container {
    width: 100%;
    min-height: 100vh;
    // background-color: #f3f3f3;
    position: relative;
    .top {
      position: relative;
      .cover-bg {
        width: 100%;
        height: 500rpx;
        .bg-img {
          width: 100%;
          height: 100%;
        }
      }
      .desc-box {
        width: 100%;
        padding: 0 30rpx;
        position: absolute;
        bottom: 50rpx; left: 50%;
        transform: translateX(-50%);
        z-index: 98;
        box-sizing: border-box;
        .desc-row {
          display: flex;
          .cover-img {
            width: 160rpx;
            height: 160rpx;
            .avatar-img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          .desc-content {
            flex: 1;
            color: #fff;
            margin-left: 20rpx;
            .title {
              font-size: 36rpx;
            }
            .desc {
              font-size: 26rpx;
              margin-top: 8rpx;
              white-space: normal;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
          }
        }
        .share-row {
          width: 100;
          display: flex;
          align-items: center;
          justify-content: space-between;
          color: #fff;
          margin-top: 20rpx;
          .video-count {
            font-size: 26rpx;
          }
          .share-icon {
            color: #fff;
            background-color: #fff;
          }
          .share-btn {
            margin: 0;
            padding: 0;
            background-color: rgba(0, 0, 0, 0);
          }
          button::after {
            border: none;
            
          }
        }
      }
      .bg {
        width: 100%;
        height: 500rpx;
        background-color: #000;
        opacity: 0.4;
        z-index: 91;
        position: absolute;
        top: 0; right: 0; bottom: 0; left: 0;
      }
    }
    .middle {
      width: 100%;
      min-height: calc(100vh - 500rpx);
      background-color: #fff;
      border-radius: 30rpx 30rpx 0 0;
      z-index: 99;
      position: absolute;
      top: 470rpx; left: 0;
      .video-box {
        width: 690rpx;
        padding: 40rpx 30rpx;
        margin: 0 auto;
      }
    }
  }
</style>